Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
The ms-rest npm package is a runtime library for REST clients generated by AutoRest. It provides functionalities for making HTTP requests, handling responses, and managing authentication, among other things.
HTTP Client
This feature allows you to send HTTP requests and handle responses. The code sample demonstrates how to create a ServiceClient instance and send a GET request to a specified URL.
const msRest = require('ms-rest');
const client = new msRest.ServiceClient();
client.sendRequest({
method: 'GET',
url: 'https://api.example.com/data'
}).then(response => {
console.log(response.body);
}).catch(err => {
console.error(err);
});
Authentication
This feature provides support for various authentication mechanisms. The code sample demonstrates how to authenticate using a service principal and then send an authenticated GET request.
const msRest = require('ms-rest');
const msRestAzure = require('ms-rest-azure');
msRestAzure.loginWithServicePrincipalSecret(clientId, secret, domain, (err, credentials) => {
if (err) return console.error(err);
const client = new msRest.ServiceClient(credentials);
client.sendRequest({
method: 'GET',
url: 'https://api.example.com/data'
}).then(response => {
console.log(response.body);
}).catch(err => {
console.error(err);
});
});
Custom Middleware
This feature allows you to add custom middleware to the request pipeline. The code sample demonstrates how to log requests and responses by adding a custom policy to the pipeline.
const msRest = require('ms-rest');
const client = new msRest.ServiceClient();
client.pipeline.addPolicy({
sendRequest: (request, next) => {
console.log('Request:', request);
return next(request).then(response => {
console.log('Response:', response);
return response;
});
}
});
client.sendRequest({
method: 'GET',
url: 'https://api.example.com/data'
}).then(response => {
console.log(response.body);
}).catch(err => {
console.error(err);
});
Axios is a promise-based HTTP client for the browser and Node.js. It provides a simple API for making HTTP requests and handling responses. Compared to ms-rest, Axios is more general-purpose and does not include built-in support for authentication or custom middleware.
Request is a simplified HTTP client for Node.js. It provides a straightforward API for making HTTP requests. While it is similar to ms-rest in terms of basic HTTP functionalities, it lacks the advanced features like authentication and custom middleware provided by ms-rest.
Node-fetch is a lightweight module that brings window.fetch to Node.js. It is focused on providing a fetch API in Node.js environments. Compared to ms-rest, node-fetch is more lightweight and does not include advanced features like authentication or custom middleware.
Infrastructure for serialization/deserialization, error handling, tracing, and http client pipeline configuration. Required by nodeJS client libraries generated using AutoRest.
npm install ms-rest
var msrest = require('ms-rest');
Features
Type checking
Validation of specified constraints
Flattening/Unflattening properties
Default Values
Model Properties marked as constant are set during serialization, irrespective of they being provided or not
Required check (If a model or property is marked required and is not provided in the object then an error is thrown)
Readonly check (If a model or property is marked readonly then it is not sent on the wire during, serialization)
Serializing Constant values
serialize an array of dictionary of primitive values
var mapper = {
type : {
name: 'Sequence',
element: {
type : {
name: 'Dictionary',
value: {
type: {
name: 'Boolean'
}
}
}
}
}
};
var array = [{ 1: true }, { 2: false }, { 1: true, 2: false, 3: true }];
var serializedArray = msRest.serialize(mapper, array, 'arrayObj');
assert.deepEqual(array, serializedArray);
var serializedProduct = msrest.serialize(mapper, productObj, 'productObject');
var deserializedArray = msRest.deserialize(mapper, serializedArray, 'serializedArrayObj');
For more examples on serialization/deserialization with complex types please take a look over here.
FAQs
Client Runtime for Node.js client libraries generated using AutoRest
The npm package ms-rest receives a total of 215,134 weekly downloads. As such, ms-rest popularity was classified as popular.
We found that ms-rest demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.